<?php

namespace App\Http\Controllers\Wechat;

use function GuzzleHttp\Promise\all;
use Illuminate\Http\Request;
use App\Models\Ad\Advert;
use App\Models\Shop\Product;
use App\Http\Controllers\Controller;

class HomeController extends Controller
{
    function __construct()
    {
        view()->share([
            '_index' => 'on'
        ]);
    }

    public function index()
    {
//        session()->flush();
//        return session()->all();
        $slides = Advert::where('category_id', '6')->orderBy("sort_order")->get();
        $banners = Advert::where('category_id', '7')->orderBy("sort_order")->get();
        $products = Product::where('is_onsale', 1)->orderBy('sort_order')->limit(4)->get();
        $total = Product::count();
        return view('wechat.index', compact('slides', 'banners', 'products','total'));
    }

    public function more(Request $request){
        $start = $request->start;
        $list = Product::where('is_onsale', 1)->orderBy('sort_order')->offset($start)->limit(1)->get();
        return array( 'result'=>$list,'status'=>1, 'msg'=>'获取成功！');
    }

}
